package com.novax.ex.ai.config;

import cn.hutool.http.HttpRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

@Configuration
public class HttpConfig {

    // 从配置中心拉取数据，拉取不到使用默认值
    @Value("${openai.chatgpt.apiurl:https://api.openai.com/v1/chat/completions}")
    private String apiUrl;

    @Value("${openai.chatgpt.apiKey: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}")
    private String apiKey;

    @Value("${openai.chatgpt.model:gpt-3.5-turbo}")
    private String model;

    @Bean
    @Scope("singleton")
    public HttpRequest getHttpRequest() {

        return HttpRequest.post(apiUrl)
                .header("Content-Type", "application/json")
                .header("Authorization", "Bearer " + apiKey)
                .setHttpProxy("127.0.0.1", 7890);

    }
}
